<extend name="./Application/Admin/View/Layouts/application.html"/>


<block name="content">
    <div class="admin-content" id="app">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">编辑菜单与权限</strong> /
                <small>Edit Menus & Rules</small>
            </div>
        </div>

        <hr>

        <div class="am-g">

            <div class="am-u-lg-6">
                <div class="am-panel am-panel-default">
                    <div class="am-panel-bd ">
                        <form class="am-form" data-am-validator>

                            <input type="hidden" name="id" value="{{$rule.id}}">

                            <div id="_method"></div>
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    上级菜单
                                </div>
                                <div class="am-u-sm-8 am-u-md-9 am-u-end col-end">
                                    <select name="parent_id" id="parent_id">

                                        <!--<eq name="rule.parent_id" value="0">-->
                                        <option value="0">顶级菜单</option>
                                        <!--<else/>-->
                                        <volist name="menus" id="menu">
                                            <option value="{{$menu.id}}"
                                            <eq name="menu.id" value="$rule.parent_id">selected</eq>
                                            >{{$menu.title}}
                                            </option>
                                            <volist name="menu.children" id="children">
                                                <option value="{{$children.id}}"
                                                <eq name="children.id" value="$rule.parent_id">selected</eq>
                                                >&nbsp;&nbsp;&nbsp;&nbsp;|--{{$children.title}}</option>
                                            </volist>
                                        </volist>
                                        <!--</eq>-->

                                    </select>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    图标
                                </div>
                                <div class="am-u-sm-8 am-u-md-9 am-text-right">
                                    <div class="am-form-group am-form-icon">
                                        <i class="permission.icon"></i>
                                        <input type="text" class="am-input-sm" id="icon" value="{{$rule.icon}}"
                                               placeholder="请输入图标的class">
                                    </div>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    菜单名称
                                </div>
                                <div class="am-u-sm-8 am-u-md-9">
                                    <input type="text" class="am-input-sm" id="title" value="{{$rule.title}}"
                                           placeholder="请输入菜单名称">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    权限名称
                                </div>
                                <div class="am-u-sm-8 am-u-md-9">
                                    <textarea rows="4" id="name" placeholder="请输入权限名称">{{$rule.name}}</textarea>
                                </div>
                            </div>

                            <div class="am-margin">
                                <button type="submit" class="am-btn am-btn-primary am-radius submit">保 存</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="js">
    <script>
        $(function () {
            //ajax编辑
            $('.submit').click(function () {
                var info = {
                    id: $('input:hidden').val(),
                    parent_id: $('#parent_id').val(),
                    icon: $('#icon').val(),
                    title: $('#title').val(),
                    name: $('#name').val()
                };

                $.ajax({
                    type: 'POST',
                    url: "{{:U('edit_rule')}}",
                    data: info,
                    success: function (info) {
                        if (info.status == 1) {
                            alert(info.msg);
                            location.href = "{{:U('AuthSet/rule_manage')}}";
                        } else {
                            alert(info.msg);
                        }
                    }
                });
                return false;
            })
        })
    </script>
</block>